﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.Mvc;
using Zsnd.Helpers;

namespace MaymuseMS.Controllers {
    [Authorize]
    public class HomeController : CustomController {
        public ActionResult Index() {
            //return View("~/Views/ProductItem/Index.cshtml");
            return View("~/Views/Shared/_Layout.cshtml");
        }

        //[ChildActionOnly]
        //public ActionResult Desktop() {
        //    return PartialView("Desktop");
        //}


        public ActionResult LeftMenu() {
            string[] imgs = { "application_osx.png", 
                                "asterisk_orange.png", 
                                "book_addresses.png", 
                                "bell.png", 
                                "book.png", 
                                "book_open.png", 
                                "box.png", 
                                "calculator.png", 
                                "page.png", "page_white_cd.png", "page_white_paste.png", "" };

            if (Roles.IsUserInRole("systemmanagers")) {
                var jsonDataSM = new {
                    img = imgs.Where((n, i) => i < 1),
                    span = new object[] { "用户管理" },
                    url = new object[] { "/user/index" }
                };
                return Json2(jsonDataSM);
            }
            if (Roles.IsUserInRole("depositorymanagers")) {
                var jsonDataDM = new {
                    img = imgs.Where((n, i) => i < 7),
                    span = new object[] { "零部件管理", "半成品管理", "成品管理", "配置单管理", "零部件库存管理", "半成品库存管理", "成品库存管理" },
                    url = new object[] { "/parts/index", "/semifinished/index", "/finished/index", "/configuration/index", "/partsdepository/index", "/semifinisheddepository/index", "/finisheddepository/index" }
                };
                return Json2(jsonDataDM);
            }
            if (Roles.IsUserInRole("depositoryusers")) {
                var jsonDataDU = new {
                    img = imgs.Where((n, i) => i < 11),
                    span = new object[] { "采购项查看", "零部件入库", "半成品入库", "成品入库", 
                        "零部件出库", "半成品出库", "成品出库", "生产出库", "零部件库存查看", "半成品库存查看", "成品库存查看" },
                    url = new object[] { "/orderitem/index", "/partsindepository/index", "/semifinishedindepository/index", "/finishedindepository/index",
                        "/partsoutdepository/index", "/semifinishedoutdepository/index", "/finishedoutdepository/index", "/produceorder/index", "/partsdepository/index", "/semifinisheddepository/index", "/finisheddepository/index" }
                };
                return Json2(jsonDataDU);
            }
            if (Roles.IsUserInRole("purchasemanagers")) {
                var jsonDataPM = new {
                    img = imgs.Where((n, i) => i < 8),
                    span = new object[] { "零部件库存", "半成品库存", "成品库存",
                        "供应商管理", "供货表管理", "采购排产单管理", "采购明细查询", "数据汇总"},
                    url = new object[] { "/partsdepository/index", "/semifinisheddepository/index", "/finisheddepository/index",
                        "/supplier/index", "/productItem/index", "/order/index", "/orderitem/index", "/statistic/index" }
                };
                return Json2(jsonDataPM);
            }
            if (Roles.IsUserInRole("saleusers")) {
                var jsonDataSU = new {
                    img = imgs.Where((n, i) => i < 1),
                    span = new object[] { "成品库存" },
                    url = new object[] { "/finisheddepository/index" }
                };
                return Json2(jsonDataSU);
            }
            var jsonData = new {
                img = new object[] { },
                span = new object[] { "用户配置", "项目配置", "领料修改授权" },
                url = new object[] { "/supplier/index", "/partsdepository/index", "/outinventory/index" }
            };
            return Json2(jsonData);
        }
    }
}
